package com.slz.crm.pojo.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.slz.crm.pojo.ao.Privacy;
import com.slz.crm.pojo.entity.UserEntity;
import lombok.Data;

import java.time.LocalDateTime;

/**
 * 系统用户VO
 */
@Data
public class UserVO implements Privacy {
    private Long id;
    private String realName;
    private String phone;
    private String email;
    private Long deptId;
    private Long roleId;
    private String roleName;
    private Integer status;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime updateTime;

    @Override
    public Boolean email() {
        this.email = "***";
        return true;
    }


    @Override
    public Boolean phone() {
        this.phone = "***";
        return true;
    }

    /**
     * 从Entity创建VO
     * @param entity 用户实体
     * @return UserVO
     */
    public static UserVO fromEntity(UserEntity entity) {
        if (entity == null) {
            return null;
        }

        UserVO vo = new UserVO();
        vo.setId(entity.getId());
        vo.setRealName(entity.getRealName());
        vo.setPhone(entity.getPhone());
        vo.setEmail(entity.getEmail());
        vo.setDeptId(entity.getDeptId());
        vo.setRoleId(entity.getRoleId());
        vo.setStatus(entity.getStatus());
        vo.setCreateTime(entity.getCreateTime());
        vo.setUpdateTime(entity.getUpdateTime());

        return vo;
    }

}
